package com.forg.mvc.core.common;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropUtil {

    private static Properties prop = new Properties();

    private static Logger logger = LoggerFactory.getLogger(PropUtil.class);

    static {

        try {
            InputStream is = ClassUtil.getClassLoader().getResourceAsStream("system.properties");
            prop.load(is);
            logger.debug("load system.properties done.");
            is.close();
        } catch (FileNotFoundException e) {
            logger.warn("system.properties not found!");
        } catch (Exception e) {
        }
    }

    public static String getString(String k) {
        return getString(k, null);
    }

    public static String getString(String k, String defaultVal) {
        return prop.getProperty(k, defaultVal);
    }

    public static Integer getInt(String k) {
        return getInt(k, 0);
    }

    public static Integer getInt(String k, Integer defaultVal) {

        String r = prop.getProperty(k, defaultVal + "");

        Integer intVal = Integer.parseInt(r);

        return intVal;
    }

    public static Boolean getBool(String k) {
        return getBool(k, false);
    }

    public static Boolean getBool(String k, boolean defaultVal) {
        String r = prop.getProperty(k, Boolean.toString(defaultVal));

        boolean boolVal = Boolean.parseBoolean(r);
        return boolVal;
    }

}
